﻿using Microsoft.Data.Edm.Values;
using System;
namespace Microsoft.Data.Edm.EdmToClrConversion
{
    /// <summary>
    /// Represents a delegate for creating an instance of CLR type based on <see cref="T:Microsoft.Data.Edm.Values.IEdmValue" /> and <see cref="T:System.Type" />.
    /// The delegate can be used to create CLR instances of polymorphic types.
    /// </summary>
    /// <param name="edmValue">The <see cref="T:Microsoft.Data.Edm.Values.IEdmStructuredValue" /> for which the <paramref name="objectInstance" /> needs to be created.</param>
    /// <param name="clrType">The expected CLR type of the object instance. In case of polymorphic properties and collections this may be a base type.</param>
    /// <param name="converter">The converter instance calling this delegate.</param>
    /// <param name="objectInstance">The output parameter returning a CLR object instance created for the <paramref name="edmValue" />.</param>
    /// <param name="objectInstanceInitialized">The output parameter returning true if all properties of the created <paramref name="objectInstance" /> are initialized.
    /// False if properties of the created instance should be initialized using the default <see cref="T:Microsoft.Data.Edm.EdmToClrConversion.EdmToClrConverter" /> logic.</param>
    /// <returns>True if the delegate produced a desired <paramref name="objectInstance" />.
    /// If delegate returns false, the default <see cref="T:Microsoft.Data.Edm.EdmToClrConversion.EdmToClrConverter" /> logic will be applied to create and populate a CLR object instance.</returns>
    public delegate bool TryCreateObjectInstance(IEdmStructuredValue edmValue, Type clrType, EdmToClrConverter converter, out object objectInstance, out bool objectInstanceInitialized);
}